package yhao.infra.web.common.enumsmap.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import yhao.infra.apilist.RequestResult;
import yhao.infra.web.common.enumsmap.ApplicationSelectInitBean;
import yhao.infra.web.common.enumsmap.annotation.ConditionalOnSelectable;

import java.util.stream.Collectors;
import java.util.stream.Stream;


/**
 * @author wuweipeng
 * @author liwan
 * @date 2021/7/20 9:16
 */

@RestController
@RequestMapping(value = "/enumMapping/*", produces = {"application/json;charset=UTF-8"})
@ConditionalOnSelectable
public class CommonEnumMappingController {

    @Autowired
    private ApplicationSelectInitBean applicationSelectInitBean;

    @GetMapping("/get")
    public RequestResult get(@RequestParam String enumClasses) {
        return new RequestResult(Stream.of(enumClasses.split(",")).collect(Collectors.toMap(String::toString, this.applicationSelectInitBean::getSelect)));
    }

}
